package com.affablebeans.model.repository;

import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import com.affablebeans.model.bll.DefaultTrueValidator;
import com.affablebeans.model.bll.GenericEntityBLL;
import com.affablebeans.model.dal.OrderDAL;
import com.affablebeans.model.entity.Order;

/**
 * 
 * @author Bora SAYINER
 * @since Jan 26, 2015 11:40:05 PM
 * @version 1.0.0
 */
public class Orders {

	private final GenericEntityBLL<Order> OrderBLL;
	private final OrderDAL orderDAL;

	public Orders(DataSource dataSource) {
		orderDAL = new OrderDAL(dataSource);
		DefaultTrueValidator<Order> trueValidator = new DefaultTrueValidator<Order>();
		this.OrderBLL = new GenericEntityBLL<Order>(orderDAL, trueValidator);
	}

	public boolean insertOrder(Order entity) throws SQLException {
		return OrderBLL.insertEntity(entity);
	}

	public boolean updateOrder(Order entity) throws SQLException {
		return OrderBLL.updateEntity(entity);
	}

	public boolean deleteOrder(Order entity) throws SQLException {
		return OrderBLL.deleteEntity(entity);
	}

	public Order findOrderById(int id) throws SQLException {
		return OrderBLL.findEntityById(id);
	}

	public List<Order> getAllOrders() throws SQLException {
		return OrderBLL.getAllEntities();
	}

	public List<Order> findOrderByCustomer(int id) throws SQLException {
		return orderDAL.findByCustomer(id);
	}

	public int getCount() throws SQLException {
		return OrderBLL.getEntitiesCount();
	}
}
